package cn.edu.pzhu.javaweb.dao.imp;

import java.sql.Connection;
import java.util.List;

import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

import cn.edu.pzhu.javaweb.dao.FileMsgDao;
import cn.edu.pzhu.javaweb.pojo.FileMsg;
import cn.edu.pzhu.javaweb.util.DruidUtils;

public class FileMsgDaoimp implements FileMsgDao{

	private JdbcTemplate template = new JdbcTemplate(DruidUtils.getDataSource());
	
	public FileMsgDaoimp() {
		// TODO Auto-generated constructor stub
	}

	@Override
	public int insert(FileMsg entity) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int deleteById(Integer id) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int update(FileMsg entity) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public FileMsg selectById(Integer id) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<FileMsg> selectAll() {
		String sql = "select * from filemsg";
		try {
			return template.query(sql, new BeanPropertyRowMapper<>(FileMsg.class));
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}

	@Override
	public int batchInsert(List<FileMsg> entities) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int batchDelete(List<Integer> ids) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int insert(FileMsg entity, Connection con) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public List<FileMsg> selectByRange(int start, int length) {
		String sql = "select * from filemsg limit ? offset ?";
		try {
			return template.query(sql, new BeanPropertyRowMapper<>(FileMsg.class),length,start);
		}catch(Exception e) {
			e.printStackTrace();
			return null;
		}
	}

}
